<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript" src="loadxmldoc.js"></script>
</head>

<body>
<script type="text/javascript">
xmlDoc=loadXMLDoc("books.xml");

//lay node dau tien
root=xmlDoc.documentElement
document.write("<-"+root.nodeName+"-> <br />");

x=root.childNodes;//lay duoc cac node book, chua vao trong df
for (i=0;i<x.length;i++)
{ 
	if (x[i].nodeType==1)
	{//Process only element nodes (type 1),node do ton tai
		//lay attribute ben trong cap the <book category='...' >
		att=x[i].attributes;
		attval=att.getNamedItem("category").nodeValue;
		document.write("__<-"+x[i].nodeName+ " category= '"+attval+ "' -> <br />");//book la node cap 1, co ten la book, khong co gia tri! vi chi lay dc node book ben ngoai   
		 y=x[i].childNodes;//vao ... cap the <book>...<book>, lay tat ca cac ten node
		  for (j=0;j<y.length;j++)
			{ 
				if (y[j].nodeType==1)
				{//Process only element nodes (type 1) 
					 document.write("____<-/"+y[j].nodeName+"->"); //lay ten node hien thoi
					  document.write(y[j].childNodes[0].nodeValue);//y[i] la cap the <title>...<title>, childNodes[0] de vao trong..., lay gia tri dau tien
					  document.write("<-/"+y[j].nodeName+"-> <br />")
				  
				 } 
			}
			 document.write("__<-/"+x[i].nodeName+"-> <br />")
	  } 
}
document.write("<-/"+root.nodeName+"-> <br />");

</script>
</body>
</html>
